package com.tsll.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tsll.dao.PurchaseInfoMapper;
import com.tsll.entity.PurchaseInfo;
import com.tsll.service.PurchaseInfoService;
import com.tsll.vo.PurchaseFormVo;
import com.tsll.vo.PurchaseInfoVo;
import com.tsll.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Tian
 * @version: 1.0
 * @since: 1.0
 * @date: 2024/3/21/14:31
 */
@Service
public class PurchaseInfoServiceImpl implements PurchaseInfoService {

    @Autowired
    PurchaseInfoMapper purchaseinfoMapper;
    /**
     * 查询采购信息
     * @return
     */
    @Override
    public Result selectAll(Integer current, Integer pageSize, PurchaseInfoVo purchaseInfoVo) {
        PageHelper.startPage(current,pageSize);
        List<PurchaseInfo> purchaseinfos = purchaseinfoMapper.selectAll(purchaseInfoVo);
        PageInfo<PurchaseInfo> purchaseinfoPageInfo = new PageInfo<>(purchaseinfos);
        return new Result(200,"查询采购信息成功了",purchaseinfoPageInfo);
    }

    /**
     * 添加采购申请信息
     */
    @Override
    public int insertPurchaseInfo(PurchaseFormVo purchaseFormVo, Integer id) {
        return purchaseinfoMapper.insertPurchaseInfo(purchaseFormVo, id);
    }

    /**
     * 根据采购申请id删除信息
     * @param id
     * @return
     */
    @Override
    public int deletePurchaseInfoId(Integer id) {
        return purchaseinfoMapper.deletePurchaseInfoId(id);
    }

    /**
     * 查询未审核的信息
     * @param current
     * @param pageSize
     * @param purchaseInfoVo
     * @return
     */
    @Override
    public Result selectByExamineStatus(Integer current, Integer pageSize, PurchaseInfoVo purchaseInfoVo) {
        PageHelper.startPage(current,pageSize);
        List<PurchaseInfo> purchaseinfos = purchaseinfoMapper.selectByExamineStatus(purchaseInfoVo);
        PageInfo<PurchaseInfo> purchaseinfoPageInfo = new PageInfo<>(purchaseinfos);
        return new Result(200,"查询采购信息成功了",purchaseinfoPageInfo);
    }

    /**
     * 根据id修改审核状态
     * @param id
     * @return
     */
    @Override
    public Result updateExamineStatus(Integer id,Integer examinestatus) {
        purchaseinfoMapper.updateExamineStatus(id,examinestatus);
        return new Result(200,"修改成功",null);
    }


    /**
     * 驳回申请
     * @param purchaseInfo
     * @return
     */
    public Result updateReject(PurchaseInfo purchaseInfo){
        purchaseinfoMapper.updateReject(purchaseInfo);
        return  new Result(200,"修改成功",null);
    }


    /**
     * 采购图书
     * @param id
     * @return
     */
    public  Result purchaseBook(Integer id){
        int i = purchaseinfoMapper.updateStatusById(id);
        return new Result(200,"购买成功",null);

    }
}
